package org.jod.spike.swing;

import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class SliderWithToolTipExample extends JFrame {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public SliderWithToolTipExample() {
        super("Mad Level");  
        
        JSlider s = new JSlider();
        s.setOrientation(JSlider.HORIZONTAL);
        s.setMaximum(100);
        s.setMinimum(0);
        
        s.setValue(50);
        
        
        //JSlider s = new JSlider(JSlider.HORIZONTAL, 0, 100, 50) {
            /*
          String[] tooltips = {"Call 911",
                               "Seeing red",
                               "Really mad",
                               "Ticked off",
                               "Slightly peeved",
                               "Oh bother",
                               "Feel good"};
                
          public String getToolTipText(MouseEvent e) {
            Point p = e.getPoint();
            Rectangle rect = new Rectangle();
            rect = getBounds(rect);
            int n = getLabelTable().size();
            int index = n * p.y / rect.height;
            return tooltips[index];
          }
          */
        //};
        
        s.setPaintTicks(true);
        s.setMajorTickSpacing(20);
        s.setPaintLabels( true );
        
        s.putClientProperty( "JSlider.isFilled", Boolean.TRUE ); 
            
        s.setToolTipText("CICCIO");
        s.setName("pippo");
        s.addChangeListener(   new ChangeListener() {

            public void stateChanged(ChangeEvent e) {
                    
                Object source = e.getSource();
                JSlider theJSlider = (JSlider) source;
                if (!theJSlider.getValueIsAdjusting()) {
                    
                    System.out.println(theJSlider.getValue());
                }
                
            }
            
            
        });
        
        
        getContentPane().setLayout(new FlowLayout());
        getContentPane().add(s);
      }

      public static void main (String args[]) {
        SliderWithToolTipExample f = new SliderWithToolTipExample();
        f.addWindowListener(new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
      System.exit(0);
          }
        });
        f.setSize (300, 250);
        f.setVisible(true);
      }
    }
